﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once

#include "GcmpApiFoundation.h"
#include "Ptr.h"
#include "GbmpQuickCast.h"

namespace gdmp {
    namespace api {
        class Object : public gdmp::api::Base
        {
            DEFINE_CAST_BASE(gdmp::api::Object)
        public:
            // interfaces

            // 用于检查是否有引用计数泄漏
            GCMP_API_FOUNDATION_EXPORT static size_t ObjectCount();

            // 内部用，不建议外部用，API用户直接使用Ptr=。
            template <class T>
            T* Cast() const
            {
                return static_cast<T*>(this->QueryObject(T::ClassType()));
            }

        protected:
            GCMP_API_FOUNDATION_EXPORT Object();
            GCMP_API_FOUNDATION_EXPORT virtual ~Object();
        };
    }
}

#define NEW_AS_PTR(TYPE, ...) new TYPE(__VA_ARGS__)

#define SAFE_GET_IMPL() ([this]{auto p=this->impl();VALIDATE_INTERNAL_OBJECT(p);return p;})()

